import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { UiserviceProvider } from '../../providers/uiservice/uiservice';
import { BusiserviceProvider } from '../../providers/busiservice/busiservice';

/**
 * Generated class for the ZwaddPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-zwadd',
  templateUrl: 'zwadd.html',
})
export class ZwaddPage {
  userid:any;
  zw:ZW = new ZW();
  sareaList=[];
  constructor(public navCtrl: NavController, public navParams: NavParams,public busi: BusiserviceProvider, private uiservice: UiserviceProvider) {
    this.userid = localStorage.getItem("userid");
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ZwaddPage');
  }
  zwadd(){
    if(this.zw.zwms==null){
      alert("Job Name is Empty！");
      return;
    }
    if(this.zw.title == null){
      alert("Job Description is Empty!");
      return;
    }
    if(this.zw.jnyq == null){
      alert("Skill Requirements are Empty!");
      return;
    }
    this.zw.userid=this.userid;
    this.uiservice.showLoading();
    this.busi.zwadd(this.zw).subscribe(
      data=>{
        this.uiservice.hideLoading();
        if(data._success){
          this.uiservice.showToast("Save Successfully!");
        }else{
          this.uiservice.showAlert(data._message);
        }
      },
      error=>{
        this.uiservice.hideLoading();
        this.uiservice.showAlert("Net Error");
      }
    );
  }
  changearea(){
    if(this.zw.sheng == 'Melaka'){
      this.sareaList = [];
      this.sareaList.push("Batu Berendam");
      this.sareaList.push("Bukit Katil");
      this.sareaList.push("Cheng");
      this.sareaList.push("Krubong");
      this.sareaList.push("Melaka Town");
      this.sareaList.push("Aeon bandaraya");
    }else{
      this.sareaList = [];
    }
  }
}
class ZW{
  userid:any;
  title:any;
  zwms:any;
  jnyq:any;
  zzlx:any;
  gz:any;
  sheng:any;
  shi:any;
}
